package com.slaoren.mvvmexamp.ui

import android.content.res.Configuration
import android.view.View
import android.widget.Toast
import com.slaoren.mvvmexamp.R
import com.slaoren.mvvmexamp.databinding.FragmentConfigurationChangedBinding
import com.slaoren.mvvmexamp.vm.DemoViewModel

class MvvmConfigurationChangedFragment:BaseFragment<FragmentConfigurationChangedBinding, DemoViewModel>() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_configuration_changed
    }

    override fun setView() {
        mBinding.vm = mViewModel
        mBinding.clPortrait.visibility = View.VISIBLE
        mBinding.clLandscape.visibility = View.GONE
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(requireContext(), "竖屏", Toast.LENGTH_SHORT).show()
            mBinding.clPortrait.visibility = View.VISIBLE
            mBinding.clLandscape.visibility = View.GONE
        }else{
            Toast.makeText(requireContext(), "横屏", Toast.LENGTH_SHORT).show()
            mBinding.clPortrait.visibility = View.GONE
            mBinding.clLandscape.visibility = View.VISIBLE
        }
    }
}